home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / util / cdity / ModeProSrc.lha / Prefs / MPPalette.c < prev    next >
C/C++ Source or Header  |  1998-08-08  |  3KB  |  107 lines

  1. #include "mppexterns.h"
  2. #include <proto/gadtools.h>
  3. #include <proto/graphics.h>
  4. #include <clib/extras_protos.h>
  5. #include <extras/layoutgt.h>
  6. #include <extras/ext_text.h>
  7.  
  8. #include <clib/extras/palettereq_protos.h>
  9. #include <extras/palettereq.h>
  10.  
  11. extern  struct PaletteRequest *PalettePReq;
  12.  
  13. void PaletteReq(struct DefaultNode *DN)
  14. {
  15.   struct DimensionInfo dim;
  16.   struct Screen *pscr;
  17.   STRPTR pwintitle,pwinfmt;
  18.   LONG pwinfmtlen;
  19.   WORD dripens[DRIPENS+1];
  20.   WORD swidth=320,sheight=200;
  21.   LONG l;
  22.   struct Requester *req;
  23.  
  24.   pwinfmt=GetString(MSG_REQ_EDIT_PALETTE);
  25.   pwinfmtlen=strlen(pwinfmt);
  26.   if(pwintitle=AllocVec(pwinfmtlen+strlen(DN->Def_Node.ln_Name)+1,MEMF_PUBLIC|MEMF_CLEAR))
  27.     sprintf(pwintitle,pwinfmt,DN->Def_Node.ln_Name);
  28.   
  29.   if(DN->Look3D)
  30.   {
  31.     for(l=0;l<DRIPENS;l++)
  32.       dripens[l]=DN->Pens[l];
  33.     dripens[DRIPENS]=~0;
  34.   }
  35.   else
  36.     dripens[0]=~0;
  37.  
  38.   req=Busy(Win);  
  39.  
  40.   if(GetDisplayInfoData(0,(UBYTE *)&dim,sizeof(dim),DTAG_DIMS,DN->ModeID))
  41.   {
  42.     swidth  =max(swidth ,dim.Nominal.MaxX);
  43.     sheight =max(sheight,dim.Nominal.MaxY);
  44.   }
  45.   
  46.   if(pscr=OpenScreenTags(0,SA_Depth     ,DN->Depth,
  47.                            SA_DisplayID ,DN->ModeID,
  48.                            SA_Pens      ,dripens,
  49.                            SA_Overscan  ,OSCAN_TEXT,
  50.                            SA_Width     ,swidth,
  51.                            SA_Height    ,sheight,
  52.                            SA_Title     ,pwintitle,
  53.                            SA_AutoScroll,TRUE,
  54.                            SA_ModeProNode,DN,
  55.                            TAG_DONE))
  56.   {
  57.     LONG colors;
  58.     
  59.     colors=1<<(pscr->RastPort.BitMap->Depth);
  60.     
  61.     if(!PalettePReq)
  62.     {
  63.       PalettePReq=PR_AllocPaletteRequest(
  64.                   PR_TextAttr,        TAttr,
  65.                   TAG_DONE);
  66.     }
  67.     
  68.     if(PalettePReq)
  69.     {
  70.       struct RGB *newpalette;
  71.       
  72.       if(newpalette=AllocVec(sizeof(struct RGB)*colors,MEMF_CLEAR|MEMF_PUBLIC))
  73.       {
  74.         if(DN->Palette)
  75.           CopyMem(DN->Palette,newpalette,sizeof(struct RGB)*DN->Colors);
  76.           
  77.         if(PR_DoPaletteRequest(PalettePReq, 
  78.                           PR_Screen,            pscr,
  79.                           PR_Colors,            colors,
  80.                           PR_Title,             pwintitle,
  81.                           PR_InitialLeftEdge,   0,
  82.                           PR_InitialTopEdge,    pscr->BarHeight+1,
  83.                           PR_InitialWidth,      pscr->Width,
  84.                           PR_InitialHeight,     pscr->Height-pscr->BarHeight-1,
  85.                           PR_InitialPalette,    (DN->Palette?newpalette:0),
  86.                           TAG_DONE))
  87.         {
  88.           APTR dummy;
  89.           
  90.           dummy=DN->Palette;
  91.           DN->Palette=newpalette;
  92.           newpalette=dummy;
  93.  
  94.           DN->Colors=colors;
  95.           CopyMem(PalettePReq->pr_Palette,DN->Palette,sizeof(struct RGB)*colors);          
  96.         }
  97.         FreeVec(newpalette);
  98.       }
  99.     }
  100.     CloseScreen(pscr);
  101.   }
  102.   FreeVec(pwintitle);
  103.   
  104.   NotBusy(Win,req);
  105. }
  106.  
  107.